# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=ccache
pkgver=4.10.2
pkgrel=0
pkgdesc="fast C/C++ compiler cache"
url="https://ccache.dev/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	asciidoctor
	cmake
	doctest-dev
	hiredis-dev
	linux-headers
	perl
	samurai
	xxhash-dev
	zstd-dev
	"
checkdepends="bash util-linux-misc python3"
subpackages="$pkgname-doc"
source="https://github.com/ccache/ccache/releases/download/v$pkgver/ccache-$pkgver.tar.xz
	ioctl.patch
	"

prepare() {
	default_prepare

	# The riscv64 builder seems to have setgid bit set,
	# which causes tests 2, 22, and 34 to fail.
	chmod -v -s .
}

build() {
	cmake -B build -G Ninja \
		-DCCACHE_DEV_MODE=OFF \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build
}

check() {
	case "$CARCH" in
		s390x) ctest --test-dir build -E "(unittest)";;
		*) ctest --test-dir build;;
	esac
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	local link=
	mkdir -p "$pkgdir"/usr/lib/ccache/bin

	for link in cc gcc g++ cpp c++ $CHOST-cc $CHOST-gcc \
		$CHOST-g++ $CHOST-c++ c89 c99; do
		ln -sf ../../../bin/ccache "$pkgdir"/usr/lib/ccache/bin/$link
	done
}

sha512sums="
3815c71d7266c32839acb306763268018acc58b3bbbd9ec79fc101e4217c1720d2ad2f01645bf69168c1c61d27700b6f3bb755cfa82689cca69824f015653f3c  ccache-4.10.2.tar.xz
9201b2c160b5f544ee985c372b9ab25dda1612d94e1018fcc4900bce7ee4741322a257b4799e0d2f6f1b9ccc05b4aa3aa227778f36399de39d4a5d7b64ea9863  ioctl.patch
"
